<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="{{ url_for('static', filename='bootstrap-4.6.2-dist/css/bootstrap.min.css') }}">
    <title>NAS</title>
    <script>
        function confirmDelete() {
            return confirm("确定要删除该文件吗？");
        }
    </script>
</head>
<body>
    <div class="container mt-4">
        <h1 class="mb-4">NAS</h1>
        
        <h2>当前路径: {{ current_path }}</h2>

        <h2 class="mt-4">上传文件</h2>
        <form action="/upload" method="post" enctype="multipart/form-data" class="mb-3">
            <div class="form-group">
                <input type="file" name="file" class="form-control-file">
                <input type="hidden" name="current_path" value="{{ current_path }}">
            </div>
            <button type="submit" class="btn btn-primary">上传</button>
        </form>

        <h2 class="mt-4">新建文件夹</h2>
        <form action="/create_folder" method="post" class="mb-3">
            <div class="form-group">
                <input type="text" name="folder_name" class="form-control" placeholder="文件夹名称" required>
                <input type="hidden" name="current_path" value="{{ current_path }}">
            </div>
            <button type="submit" class="btn btn-secondary">创建</button>
        </form>

        <h2 class="mt-4">文件列表</h2>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>名称</th>
                    <th>大小 (字节)</th>
                    <th>最后修改时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for file in files %}
                <tr>
                    <td>
                        {% if file.is_dir %}
                            <img src="{{ url_for('static', filename='folder-icon.png') }}" alt="文件夹" style="width: 20px; height: 20px;">
                            <a href="{{ url_for('index', path=current_path + '/' + file.name) }}">{{ file.name }}</a>
                        {% else %}
                            {{ file.name }}
                        {% endif %}
                    </td>
                    <td>{{ file.size }}</td>
                    <td>{{ file.modified_time }}</td>
                    <td>
                        <form action="/download/{{ file.name }}" method="get" style="display:inline;">
                            <input type="hidden" name="current_path" value="{{ current_path }}">
                            <button type="submit" class="btn btn-info btn-sm">下载</button>
                        </form>
                        <form action="/delete/{{ file.name }}" method="post" style="display:inline;" onsubmit="return confirmDelete();">
                            <input type="hidden" name="current_path" value="{{ current_path }}">
                            <button type="submit" class="btn btn-danger btn-sm">删除</button>
                        </form>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>

    </div>

    <script src="{{ url_for('static', filename='bootstrap-4.6.2-dist/js/jquery.slim.min.js') }}"></script>
    <script src="{{ url_for('static', filename='bootstrap-4.6.2-dist/js/bootstrap.bundle.min.js') }}"></script>
</body>
</html>
